package base.tools;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import cn.schina.dbfw.dao.impl.DateParam;

public enum GetTime {
	TODAY("today"), LASTMONTH("lastmonth"), THISMONTH("thismonth"), LASTWEEK(
			"lastweek"), THISWEEK("thisweek"), YESTERDAY("yesterday");
	public String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	private GetTime(String name) {
		this.name = name;
	}

	public static DateParam time(GetTime getTime) {
		DateParam time = new DateParam();
		String startDate;
		String endDate;
		Date date = new Date();// 取时间
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, 1);
		date = calendar.getTime();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		switch (getTime) {
		case LASTMONTH:
			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -31);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			endDate = formatter.format(date);

			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -31);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			startDate = formatter.format(date);
			time.setEndDate(endDate);
			time.setStartDate(startDate);
			break;
		case THISMONTH:
			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -1);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			endDate = formatter.format(date);

			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -30);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			startDate = formatter.format(date);
			time.setEndDate(endDate);
			time.setStartDate(startDate);
			break;
		case LASTWEEK:
			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -7);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			endDate = formatter.format(date);

			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -7);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			startDate = formatter.format(date);
			time.setEndDate(endDate);
			time.setStartDate(startDate);
			break;
		case THISWEEK:
			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -1);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			endDate = formatter.format(date);

			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -7);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			startDate = formatter.format(date);
			time.setEndDate(endDate);
			time.setStartDate(startDate);
			break;
		case YESTERDAY:
			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -1);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			endDate = formatter.format(date);

			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -1);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			startDate = formatter.format(date);
			time.setEndDate(endDate);
			time.setStartDate(startDate);
			break;
		case TODAY:
			calendar = new GregorianCalendar();
			calendar.setTime(date);
			calendar.add(Calendar.DATE, -1);
			date = calendar.getTime();
			formatter = new SimpleDateFormat("yyyy-MM-dd");
			startDate=endDate = formatter.format(date);
			time.setEndDate(endDate);
			time.setStartDate(startDate);
			break;
		}
		return time;
	}

	public static void main(String[] args) {
		GetTime.time(THISMONTH);
		GetTime.time(LASTWEEK);
		GetTime.time(THISWEEK);
		GetTime.time(YESTERDAY);
		GetTime.time(TODAY);
		System.out.println();
	}
}
